<template>
    <div id=""></div>
</template>

<script>
import WS from './ws-1.1';
export default {
    name:"Index",
    data(){
        return {
            ws: null,
            url: process.env.VUE_APP_WS
        }
    },
    mounted(){
        this.ws = new WS(this.url);
        this.ws.$on('connectSuc', this.connectSuc)
        this.ws.$on('message', this.message);
        this.ws.$on('error', this.error);
        this.ws.$on('close', this.close);
    },
    methods:{
        connectSuc(e, socket) {
            socket.send('client: socket connect success')
        },
        message(e) {
            if(!e.data){return}
            console.log('客户端接收消息：', e.data)
        },
        error(){
            console.log('连接错误')
        },
        close(){
            console.log('连接关闭')
        }
    }
}
</script>
<style lang="scss">

</style>